/**
 * Created by Administrator on 2017/7/27.
 */
angular.module('module.activity_list', [])
    .config(['$stateProvider', function ($stateProvider) {
        $stateProvider
            .state('activity_list', {
                params: {originatorId: null},
                url: '/activity_list',
                templateUrl: 'view/activity_list.html',
                controller: 'activity_list_controller'
            })
    }])
    .controller('activity_list_controller', ["$scope", '$state', "$stateParams", 'ActivityService', 'OriginatorService', "ActiveEnrollService",
        function ($scope, $state, $stateParams, ActivityService, OriginatorService, ActiveEnrollService) {
            $(".datetimepicker").remove();
            console.log('activity_list_controller启动成功');

            var query_terms = {
                // originatorId:$stateParams.originatorId,
                userId: 1,
                enrollState: 0,
                pageNum: 1
            };

//分页模块开始，该模块需要配置get_pagesum函数以及get_list_data_by_pagenum函数,并依赖angularjs以及util.controller.js(晓峰的工具函数库)-------------------------------------------------------------------------------------------------------------------

            // 页码部分初始化开始
            var pagesum;
            $scope.pagenum_list = [];
            var current_page = 1;
            $scope.pagination_show = true;

            /*//获取总页数(该函数附带回调函数，用于解决异步问题)
            function get_pagesum(sfun, efun) {

            }
*/
            // 根据页数拿到该页题目列表函数
            var set_page_data_by_pagenum = function (pagenum,sfun,efun) {
                query_terms.pageNum = pagenum;
                ActivityService.getActivityListByUserEnrollState(query_terms,function (data) {
                    console.log(data);
                    $scope.Activity_list =data.fullActiveList;
                    pagesum=data.pageCount;
                    $scope.pagenum_list = create_pagenum_list(pagesum, pagenum);
                    $scope.pagination_show = pagesum == 0 || pagesum == 1;
                    if (sfun){
                        sfun()
                    }
                },efun);
            };

            //从这里开始与页面数据无关
            //刷新数据函数
            function refresh_data() {
                // configure_pagenum_list(current_page);
                set_page_data_by_pagenum(current_page);
            }
            refresh_data();

            //配置pagenum_list函数
            var configure_pagenum_list = function (pagenum) {
                get_pagesum(function () {
                });
            };

            //页码交互事件

            //页码点击函数
            $scope.page_click = function (pagenum) {
                current_page = pagenum;
                refresh_data();
            };

            //向前翻页函数
            $scope.page_up = function () {
                if (current_page > 1) {
                    current_page = current_page - 1;
                    refresh_data();
                } else {
                    alert("已经是第一页了")
                }
            };

            //向后翻页函数
            $scope.page_down = function () {
                if (current_page < pagesum) {
                    current_page = current_page + 1;
                    refresh_data();
                } else {
                    alert("已经是最后一页了")
                }
            };

// 分页模块结束------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//          根据用户参加活动状态刷新数据
            $scope.getActivityListByUserEnrollState=function(EnrollState) {
                query_terms.enrollState=EnrollState;
                refresh_data();
            }


// 服务测试部分（如无意外不再启用，仅做备用模块）
 /*           //ActivityService

            /!*ActivityService.addActivity({
                activeContents: "YYY",
                activeId: 1,
                activeLimit: "长得帅",
                activeName: "爬山",
                activePlace: "旗山",
                activeReward: "",
                activeState: "4",
                activeTime: 1499940005000,
                auditMessage: "",
                cancelMessage: "",
                enrolmentDetails: "12",
                originatorId: 1
            },function (data) {
                console.log("ActivityService.addActivity()成功返回",data);
            },function (data) {
                console.log("ActivityService.addActivity()失败返回",data)
            });*!/

            /!*ActivityService.deleteActivity(2,function (data) {
                console.log("ActivityService.deleteActivity()成功返回=",data)
            },function (data) {
                console.log("ActivityService.deleteActivity()失败返回",data)
            });*!/

            /!*ActivityService.updateActivity({
                "activeId": 2,
                "activeName": "打老虎",
                "originatorId": 1,
                "activeContents": "12345，上山打老虎",
                "activeTime": null,
                "activePlace": "旗山",
                "activeLimit": "无",
                "activeReward": "无",
                "enrolmentDetails": "0",
                "activeState": "1",
                "auditMessage": "",
                "cancelMessage": ""
            },function (data) {
                console.log("ActivityService.updateActivity()成功返回=",data)
            },function (data) {
                console.log("ActivityService.updateActivity()失败返回",data)
            });*!/

            /!*ActivityService.getActivity(13,function (data) {
                console.log("ActivityService.getActivity()成功返回=",data)
            },function (data) {
                console.log("ActivityService.getActivity()失败返回=",data)
            });*!/

            /!* ActivityService.getActivityList({},function (data) {
                console.log("ActivityService.getActivityList()成功返回=",data)
            },function (data) {
                console.log("ActivityService.getActivityList()失败返回=",data)
            });*!/

            /!*ActivityService.getActivityListByUserEnrollState({userId:123,enrollState:0,pageNum:1},function (data) {
                console.log("ActivityService.getActivityListByUserEnrollState()成功返回=",data)
            },function (data) {
                console.log("ActivityService.getActivityListByUserEnrollState()失败返回=",data)
            })*!/

            //OriginatorService

            /!*OriginatorService.addOriginator({
                "originatorId": 1,
                "originatorName": "xiaohu",
                "originatorProfile": "驾驶的发生",
                "originatorState": 0
            },function (data) {
                console.log("OriginatorService.addOriginator()成功返回=",data)
            },function (data) {
                console.log("OriginatorService.addOriginator()失败返回=",data)
            })*!/

            /!*OriginatorService.deleteOriginator(0,function (data) {
                console.log("OriginatorService.deleteOriginator()成功返回=",data)
            },function (data) {
                console.log("OriginatorService.deleteOriginator()失败返回",data)
            })*!/

            /!*OriginatorService.updateOriginator({
                "originatorId": 0,
                "originatorName": "xiaohu",
                "originatorProfile": "驾驶的发生",
                "originatorState": 0
            },function (data) {
                console.log("OriginatorService.updateOriginator()成功返回=",data)
            },function (data) {
                console.log("OriginatorService.updateOriginator()失败返回=",data)
            })*!/

            /!*OriginatorService.getOriginator(0,function (data) {
                console.log(" OriginatorService.getOriginator()成功返回=",data)
            },function (data) {
                console.log(" OriginatorService.getOriginator()失败返回=",data)
            })*!/

            /!*OriginatorService.getOriginatorListByState({originatorState:0},function (data) {
                console.log("OriginatorService.getOriginatorListByState()成功返回=",data)
            },function (data) {
                console.log("OriginatorService.getOriginatorListByState()失败返回=",data)
            });*!/

            //ActiveEnrollService
            /!*ActiveEnrollService.addActiveEnroll({
                "activeId": 2,
                "userId": 123,
                "enrolmentPlace": "激发",
                "enrolmentTime": 1502087283000,
                "enrolmentDetails": "YYY",
                "changeTime": 1502087283000,
                "teamName": "",
                "enrolmentState": "4",
                "auditMessage": "123"
            },function (data) {
                console.log("ActiveEnrollService.addActiveEnroll()成功返回=",data)
            },function (data) {
                console.log("ActiveEnrollService.addActiveEnroll()失败返回=",data)
            })*!/

            /!*ActiveEnrollService.deleteActiveEnroll({userId:123,activeId:1},function (data) {
                console.log("ActivityService.deleteActiveEnroll()成功返回=",data)
            },function (data) {
                console.log("ActivityService.deleteActiveEnroll()失败返回",data)
            });*!/

            /!*ActiveEnrollService.updateActiveEnroll({
                "activeId": 2,
                "userId": 123,
                "enrolmentPlace": "激发",
                "enrolmentTime": 1502087283000,
                "enrolmentDetails": "YYY",
                "changeTime": 1502087283000,
                "teamName": "",
                "enrolmentState": "0",
                "auditMessage": "123"
            },function (data) {
                console.log("ActivityService.updateActiveEnroll()成功返回=",data)
            },function (data) {
                console.log("ActivityService.updateActiveEnroll()失败返回",data)
            })*!/

            /!*ActiveEnrollService.getActiveEnroll({userId:123,activeId:1},function (data) {
                console.log("ActivityService.getActiveEnroll()成功返回=",data)
            },function (data) {
                console.log("ActivityService.getActiveEnroll()失败返回",data)
            })*!/

            /!*ActiveEnrollService.getActiveEnrollList({activeId:1,state:4},function (data) {
                console.log("ActiveEnrollService.getActiveEnrollList()成功返回=",data)
            },function (data) {
                console.log("ActiveEnrollService.getActiveEnrollList()失败返回=",data)
            })*!/

*/
        }]);